#ifndef _DNS_STRUCTS_H_
#define _DNS_STRUCTS_H_

struct Header
{
	// New random ID specifying the unique number for a given query.
	unsigned short id;

	// Packet Type : 0 : Query, 1 : Response.
	unsigned char qr:1;
	// 4 bit field specifying Exact Op Type, 0 for a standard query.
	unsigned char opCode:4;
	// Authoritative Answer. 0 for query, Used in responses for whether its an authoritave answer.
	unsigned char aa:1;
	// Truncation : 0 : Not truncated, 1 : Truncated, We will not handle truncation.
	unsigned char tc:1;
	// Recursion Desired : 0 : No. 1 : Yes, We always want recursion.
	unsigned char rd:1;
	// Recursion Available : 0 : No, 1 : Yes, Used in Response, If this is every returned 0 we quit.
	unsigned char ra:1;
	// Future Use, always 0.
	unsigned char z:3;
	// Response Code :
	//    0 : No Error.
	//    1 : Format Error.
	//    2 : Server Failure.
	//    3 : Name Error.
	//    4 : Not Implemented.
	//    5 : Refused.
	unsigned char rcode:4;

	// Number of questions, We always have 1.
	unsigned short qdcount;
	// Number of Resource Records, Used in response, we set to 0 for query.
	unsigned short ancount;
	// Number of Name Server Records, Used in response, we set to 0 for query.
	unsigned short nscount;
	// Number of Resource Records in the AR Section, Used in response, we set to 0 for query.
	unsigned short arcount;
};

struct Question
{
	// The Domain name : 3www6google3com0
	char* qname;
	// 0x0001 : Host Address,
	// 0x000f : MX Records,
	// 0x0002 : NS Record,
	unsigned short qtype;
	// Specifies class of the query, in our case 0x0001 for Internet Addresses.
	unsigned short qclass;
};

struct Answer
{
	// The Domain name : 3www6google3com
	char* name;
	// One of the type codes.  Specifies the meaning of rdata.
	unsigned short type;
	// Specifies class of rdata, in our case 0x0001 for Internet Addresses.
	unsigned short theClass;
	// The number of seconds results can be cached.
	unsigned short ttl;
	// The length of rdata.
	unsigned short rdlength;
	// The data of the response, could be of type 0x0001, 0x0005, 0x0002, 0x000f,
	char* rdata;
};

struct Query
{
	// Refers to Header Struct above.
	struct Header header;
	// Refers to Question Struct above.
	struct Question question;
};

struct Response
{
	// Refers to Header Struct above.
  struct Header header;
	// Refers to Question Struct above.
  struct Question question;
	// Refers to Answer Struct above.
  struct Answer answer;
};

#endif
